<?php

use yii\db\Migration;

class m000004_000006_create_card_attr_value extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%card_attr_value}}', [
            'id' => $this->primaryKey(),
            'uid' => $this->integer()->comment('用户编号'),
            'card_id' => $this->integer()->comment('卡编号'),
            'attr_id' => $this->integer()->notNull()->comment('属性编号'),
            'value' => $this->string(1024)->comment('属性值'),
        ]);
        $this->createIndex('fk_card_attr_value_user1_idx', '{{%card_attr_value}}', ['uid']);
        try {
            $this->addForeignKey('fk_card_attr_value_user1', '{{%card_attr_value}}', ['uid'], '{{%user}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
        $this->createIndex('fk_card_attr_value_card1_idx', '{{%card_attr_value}}', ['card_id']);
        try {
            $this->addForeignKey('fk_card_attr_value_card1', '{{%card_attr_value}}', ['card_id'], '{{%card}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
        $this->createIndex('fk_card_attr_value_card_attr1_idx', '{{%card_attr_value}}', ['attr_id']);
        try {
            $this->addForeignKey('fk_card_attr_value_card_attr1', '{{%card_attr_value}}', ['attr_id'], '{{%card_attr}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
        $this->createIndex('card_attr_value1_idx', '{{%card_attr_value}}', ['value(512)']);
    }

    public function down()
    {
        $this->dropTable('{{%card_attr_value}}');
    }
}
